package hub.cathome.controller;

import hub.cathome.entity.Like;
import hub.cathome.entity.ShotBlog;
import hub.cathome.entity.User;
import hub.cathome.service.CommentService;
import hub.cathome.service.LikeService;
import hub.cathome.service.ShotBlogService;
import hub.cathome.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;

@Controller
public class LikeController {
    @Resource(name="likeService")
    private LikeService likeService;
    @Resource(name="shotBlogService")
    private ShotBlogService shotBlogService;
    @RequestMapping("/affair/shotBlog/like")
    public void likeShotBlog(@RequestParam("blogId") int blogId, HttpSession session, HttpServletRequest request){
        User user = (User) session.getAttribute("user");
        Like like0 = likeService.getLikeByShotBlogIdAndUserId(blogId, user.getId());
        if(like0!=null){
            return;
        }
        Like like = new Like();
        like.setDate(new Date());
        like.setShotBlogId(blogId);
        like.setUser(user);
        likeService.insertLike(like);
    }
}
